﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Framework_Tool
{
    /// <summary>
    /// Interaction logic for UnitUpdate.xaml
    /// </summary>
    public partial class UnitUpdate : Page
    {
        // private MainWindow main;

        public UnitUpdate()
        {
            InitializeComponent();
            Database.FindUnitID_Update(this);
            Database.FindCourseTitle_UnitUpdate(this);
            Database.FindStfID_UnitUpdate(this);
        }

        private void mainContent_Loaded(object sender, RoutedEventArgs e)
        {
            viewUnit.FontWeight = FontWeights.Normal;
            addUnit.FontWeight = FontWeights.Normal;
            updateUnit.FontWeight = FontWeights.ExtraBold;
            deleteUnit.FontWeight = FontWeights.Normal;
            searchUnit.FontWeight = FontWeights.Normal;
        }

        private void unitUpdate_Click(object sender, RoutedEventArgs e)
        {
            Database.UpdateUnit(this);
        }

        private void viewUnitBtn_Click(object sender, RoutedEventArgs e)
        {
            UnitView unitViewWindow = new UnitView();
            unitViewWindow.Content = null;
            mainContent.Children.Add(unitViewWindow.mainContent);
        }

        private void addUnitBtn_Click(object sender, RoutedEventArgs e)
        {
            UnitAdd UnitAddWindow = new UnitAdd();
            UnitAddWindow .Content = null;
            mainContent.Children.Add(UnitAddWindow.mainContent);
        }

        private void deleteUnitBtn_Click(object sender, RoutedEventArgs e)
        {
            UnitDelete UnitDeleteWindow = new UnitDelete();
            UnitDeleteWindow.Content = null;
            mainContent.Children.Add(UnitDeleteWindow.mainContent);
        }

        private void searchUnitBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void unitIDUpdateCmbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Database.populateFields_UnitUpdate(this);
            //Database.populateTeachingList_UnitUpdate(this);
        }

        private void unitUpdate_CourseTitleCmbx_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Database.populateCourseID_UnitUpdate(this);
        }

        private void unitUpdate_StfIDCmbx_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            String name = Database.populateStfID_UnitUpdate(unitUpdate_StfIDCmbx.SelectedItem);
           unitUpdate_StfNameLbl.Content = name;
        }

        private void unitUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            Database.UpdateUnit(this);
        }

        private void cancelUnitUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            unitIDUpdateCmbx.SelectedItem = null;
            unitUpdate_StfIDCmbx.SelectedItem = null;
            unitUpdate_StfIDCmbx.SelectedItem = null;
            unitUpdate_CourseTitleCmbx.SelectedItem = null;
            crseIDUpdateLbl.Content = null;
            unitTitleUpdateTxt.Text = null;
            unitUpdateDescTxt.Text = null;
            unitStfUpdateListBox.Items.Clear();
            unitUpdate_StfNameLbl.Content = null;
            unitUpdatedLblGrid.Visibility = Visibility.Hidden;
        }

        private void addTeacher_UnitUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            foreach (String li in unitStfUpdateListBox.Items)
            {
                if (li.Substring(0,6).Equals(unitUpdate_StfIDCmbx.Text))
                {
                    return;
                }
            }
            String name = Database.populateStfID_UnitUpdate(unitUpdate_StfIDCmbx.SelectedItem);
            unitStfUpdateListBox.Items.Add(unitUpdate_StfIDCmbx.SelectedItem + " " + name);

            unitUpdate_StfIDCmbx.SelectedItem = null;
            unitUpdate_StfNameLbl.Content = null;
        }

        private void removeTeacher_Click_1(object sender, RoutedEventArgs e)
        {
            Database.DeleteTeachesRow(this);
            unitStfUpdateListBox.Items.Remove(unitStfUpdateListBox.SelectedItem);
        }
    }
}
